<?php

namespace App\Events\Listeners;

use Illuminate\Database\Events\QueryExecuted;
use Illuminate\Support\Facades\Log;

class SqlEventListener
{
    /**
     * Create the event listener.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    /**
     * Handle the event.
     * @param QueryExecuted $event
     * @return void
     */
    public function handle(QueryExecuted $event){
        $sql = $event->sql;
        if (str_contains($sql, "select") && str_contains($sql, "queue_jobs")) {
            return;
        }
        $sql = str_replace(["%","?"], ["%%","'%s'"], $event->sql);
        $msg = vsprintf($sql, $event->bindings);
        Log::channel('sqllog')->info($msg);
    }
}
